package net.zjitc.controller;

import net.zjitc.pojo.Category;
import net.zjitc.pojo.Product;
import net.zjitc.service.CategoryService;
import net.zjitc.service.Impl.CategoryServiceImpl;
import net.zjitc.service.Impl.ProductServiceImpl;
import net.zjitc.service.ProductService;
import net.zjitc.utils.dispacher.URLMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/10/26.
 */
public class IndexController {
    CategoryService categoryService=new CategoryServiceImpl();
    ProductService productService=new ProductServiceImpl();
    @URLMapping(url = "/index")
    public String showindex(HttpServletRequest request, HttpServletResponse response)
    {
        List<Category> clist=categoryService.findAllCategory();
        request.setAttribute("clist",clist);

        List<Product> newProduct=productService.findAllProduct();
        List<Product> productList=new ArrayList<Product>();
        for(Product p:newProduct)
        {
            if(p.getIs_hot()==1)
            {
                productList.add(p);
            }
        }
        request.setAttribute("hotProduct",productList);
        request.setAttribute("newProduct",newProduct);
        return "/WEB-INF/user/index.jsp";
    }

}
